package com.dgm;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.Test;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;


public class ExcelComm {

	
//	public String exportExcel(String[] selectIds) throws Exception{
//		 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd(HH时mm分ss秒)");
//		 String date = format.format(new Date());
//		 String dir = "F:\\shixun\\日志文件\\登录日志" + date + ".xls";
//		 File file = new File(dir);
//		 if(!file.getParentFile().exists()) file.getParentFile().mkdirs();
//		 WritableWorkbook book = Workbook.createWorkbook(file);  
//		 
//		//标题的excel填充框的格式
//		 WritableFont font = new WritableFont(WritableFont.createFont("宋体"), 15); 
//		 WritableCellFormat cellFormat = new WritableCellFormat(font); 
//		 cellFormat.setAlignment(Alignment.CENTRE);
//		 
//		 WritableSheet sheet = book.createSheet("登录日志", 0);  
//		 //设置列宽
//		 sheet.setColumnView(0, 10);
//		 sheet.setColumnView(1, 15);
//		 sheet.setColumnView(2, 10);
//		 sheet.setColumnView(3, 25);
//		 sheet.setColumnView(4, 25);
//		 
//		 Label label0 = new Label(0, 0, "日志ID", cellFormat); 
//		 Label label1 = new Label(1, 0, "登录者", cellFormat); 
//		 Label label2 = new Label(2, 0, "登录状态", cellFormat); 
//		 Label label3 = new Label(3, 0, "登录时间", cellFormat); 
//		 Label label4 = new Label(4, 0, "登录IP", cellFormat); 
//		 sheet.addCell(label0);
//		 sheet.addCell(label1);
//		 sheet.addCell(label2); 
//		 sheet.addCell(label3);
//		 sheet.addCell(label4);
//		 
//		 //设置每条记录的格式，字体小一点
//		 font = new WritableFont(WritableFont.createFont("宋体"), 12); 
//		 cellFormat = new WritableCellFormat(font); 
//		 cellFormat.setAlignment(Alignment.CENTRE);
//		 
//		 for(int i=0; i<selectIds.length; i++) {
//			 RzglDlrzInfoYn infoYn = (RzglDlrzInfoYn)rzglDlrzInfoYnDAO.queryForCmd("from RzglDlrzInfoYn o where o.id=?", Long.valueOf(selectIds[i]));
//			 label0 = new Label(0, i+1, String.valueOf(infoYn.getId()), cellFormat); 
//			 label1 = new Label(1, i+1, String.valueOf(infoYn.getDlrzName()), cellFormat); 
//			 label2 = new Label(2, i+1, String.valueOf(infoYn.getDlrzStatus()), cellFormat);  
//			 label3 = new Label(3, i+1, String.valueOf(infoYn.getDlrzData()), cellFormat); 
//			 label4 = new Label(4, i+1, String.valueOf(infoYn.getDlrzIp()), cellFormat); 
//			 sheet.addCell(label0);
//			 sheet.addCell(label1);
//			 sheet.addCell(label2);
//			 sheet.addCell(label3);
//			 sheet.addCell(label4);
//		 }
//		 book.write();    
//		 book.close();
//		 return dir;   
//	}
	
	@Test
	public void test1() throws Exception{
		String exportFilePath = "f:/exportFilePath.xml";
		File exportFile  = new File(exportFilePath);
		
		 WritableWorkbook book = Workbook.createWorkbook(exportFile);  
		 WritableSheet sheet = book.createSheet("导出表", 1);
		 
		
		
	}
}
